package com.collect.tanzania.zhiScene.zhiTelemarketing.zhiFollow;

import android.content.Context;

import com.collect.tanzania.zhiBase.BasePresenter;
import com.collect.tanzania.zhiBase.BaseSubscriber;
import com.collect.tanzania.zhiBean.zhiReceive.ZHIRTelemarketingFollowEntity;
import com.collect.tanzania.zhiBean.zhiSend.ZHISTelemarketingFollowListEntity;
import com.collect.tanzania.zhiBean.zhiSend.ZHISTelemarketingMarkedEntity;
import com.collect.tanzania.zhiNetApi.ZHIHttpApiProvider;
import com.collect.tanzania.zhiNetApi.ZHIHttpResponse;
import com.collect.tanzania.zhiUtils.RxSchedulers;

import java.util.ArrayList;

import javax.inject.Inject;

public class ZHITelemarketingFollowPresenter extends BasePresenter<ZHITelemarketingFollowContract.View> implements ZHITelemarketingFollowContract.Presenter {

    @Inject
    public ZHITelemarketingFollowPresenter() {

    }

    @Override
    public void getTelemarketingList(Context context, final ZHISTelemarketingFollowListEntity zhisTelemarketingFollowListEntity, boolean showLoading) {
        BaseSubscriber<ZHIHttpResponse<ArrayList<ZHIRTelemarketingFollowEntity>>> subscriber = new
                BaseSubscriber<ZHIHttpResponse<ArrayList<ZHIRTelemarketingFollowEntity>>>(context, this, showLoading) {
                    @Override
                    protected void onSuccess(Object object) {
                        try {
                            ArrayList<ZHIRTelemarketingFollowEntity> zhirTelemarketingFollowEntityArrayList = (ArrayList<ZHIRTelemarketingFollowEntity>) object;
                            mView.onGetTelemarketingList(zhirTelemarketingFollowEntityArrayList);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }

                    @Override
                    protected void onFailure(int code, String messge) {
                        showMessage(messge);
                        mView.onGetErrorInfo();
                    }
                };
        ZHIHttpApiProvider.getApi().telemarketingOrderList(zhisTelemarketingFollowListEntity)
                .compose(RxSchedulers.applySchedulers())
                .compose(mView.bindToLife())
                .subscribe(subscriber);
    }

    @Override
    public void markTelemarketing(Context context, ZHISTelemarketingMarkedEntity zhisTelemarketingMarkedEntity, boolean showLoading) {
        BaseSubscriber<ZHIHttpResponse> subscriber = new
                BaseSubscriber<ZHIHttpResponse>(context, this, showLoading) {
                    @Override
                    protected void onSuccess(Object object) {
                        try {
                            mView.onMarkTelemarketing();
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }

                    @Override
                    protected void onFailure(int code, String messge) {
                        showMessage(messge);
                        mView.onGetErrorInfo();
                    }
                };
        ZHIHttpApiProvider.getApi().markTelemarketing(zhisTelemarketingMarkedEntity)
                .compose(RxSchedulers.applySchedulers())
                .compose(mView.bindToLife())
                .subscribe(subscriber);
    }

    @Override
    public void markTelemarketingWhatsapp(Context context, ZHISTelemarketingMarkedEntity zhisTelemarketingMarkedEntity, final String mobile, final String whatsappContent) {
        BaseSubscriber<ZHIHttpResponse> subscriber = new
                BaseSubscriber<ZHIHttpResponse>(context, this, true) {
                    @Override
                    protected void onSuccess(Object object) {
                        try {
                            mView.onMarkTelemarketingWhatsapp(mobile, whatsappContent);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }

                    @Override
                    protected void onFailure(int code, String messge) {
                        showMessage(messge);
                        mView.onGetErrorInfo();
                    }
                };
        ZHIHttpApiProvider.getApi().markTelemarketing(zhisTelemarketingMarkedEntity)
                .compose(RxSchedulers.applySchedulers())
                .compose(mView.bindToLife())
                .subscribe(subscriber);
    }
}
